Home:ALL Converter>How to integrate SIP into Android?

How to integrate SIP into Android?

Ask Time:2012-09-28T15:19:10         Author:PrvN

Json Formatter

How to implement SIP protocol in Android ? there is any SDK or library available to implement it easily into Android?

Author:PrvN,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12635382/how-to-integrate-sip-into-android
Ashwani Tyagi :

Here is a third party Library with sample code. You can use this, I have used it and it works fine. ",
2012-10-08T05:24:50
Priyank Patel :

Android 2.3 or higher provides API for SIP.\n\nRefer this link for SIP in Android \n\nalso you can see DEMO project for SIP from Sample\n\nupdate:\nAndroid SDK Samples on github.\nSipDemo1, SipDemo2",
2012-09-28T07:24:49
G M Ramesh :

Search for SipDemo project in samples for android 4.0.3 SDK version(API level -15)",
2012-09-28T07:56:22
Денис Чорный :

I have been investigated this sort of problem for a long time and found out that SipManager and SipProfile are unfortunatelly poor and extremelly buggy.\n\nSo I found a Linphone library. There is a link for their wiki. I implemented it in my project using maven:\n\nrepositories {\n ...\n maven { \"https://linphone.org/maven_repository/\"}\n}\n\n\nAlso there is a sample of using it on gitlab: link here, it's pretty fresh, for now :)\n\nIf the link would crash, I just copy/paste the most important part of how to use linphone's core:\n\npublic class LinphoneService extends Service {\n private static final String START_LINPHONE_LOGS = \" ==== Device information dump ====\";\n // Keep a static reference to the Service so we can access it from anywhere in the app\n private static LinphoneService sInstance;\n\n private Handler mHandler;\n private Timer mTimer;\n\n private Core mCore;\n private CoreListenerStub mCoreListener;\n\n public static boolean isReady() {\n return sInstance != null;\n }\n\n public static LinphoneService getInstance() {\n return sInstance;\n }\n\n public static Core getCore() {\n return sInstance.mCore;\n }\n\n @Nullable\n @Override\n public IBinder onBind(Intent intent) {\n return null;\n }\n\n @Override\n public void onCreate() {\n super.onCreate();\n\n // The first call to liblinphone SDK MUST BE to a Factory method\n // So let's enable the library debug logs & log collection\n String basePath = getFilesDir().getAbsolutePath();\n Factory.instance().setLogCollectionPath(basePath);\n Factory.instance().enableLogCollection(LogCollectionState.Enabled);\n Factory.instance().setDebugMode(true, getString(R.string.app_name));\n\n // Dump some useful information about the device we're running on\n Log.i(START_LINPHONE_LOGS);\n dumpDeviceInformation();\n dumpInstalledLinphoneInformation();\n\n mHandler = new Handler();\n // This will be our main Core listener, it will change activities depending on events\n mCoreListener = new CoreListenerStub() {\n @Override\n public void onCallStateChanged(Core core, Call call, Call.State state, String message) {\n Toast.makeText(LinphoneService.this, message, Toast.LENGTH_SHORT).show();\n\n if (state == Call.State.IncomingReceived) {\n Toast.makeText(LinphoneService.this, \"Incoming call received, answering it automatically\", Toast.LENGTH_LONG).show();\n // For this sample we will automatically answer incoming calls\n CallParams params = getCore().createCallParams(call);\n params.enableVideo(true);\n call.acceptWithParams(params);\n } else if (state == Call.State.Connected) {\n // This stats means the call has been established, let's start the call activity\n Intent intent = new Intent(LinphoneService.this, CallActivity.class);\n // As it is the Service that is starting the activity, we have to give this flag\n intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n startActivity(intent);\n }\n }\n };\n\n try {\n // Let's copy some RAW resources to the device\n // The default config file must only be installed once (the first time)\n copyIfNotExist(R.raw.linphonerc_default, basePath + \"/.linphonerc\");\n // The factory config is used to override any other setting, let's copy it each time\n copyFromPackage(R.raw.linphonerc_factory, \"linphonerc\");\n } catch (IOException ioe) {\n Log.e(ioe);\n }\n\n // Create the Core and add our listener\n mCore = Factory.instance()\n .createCore(basePath + \"/.linphonerc\", basePath + \"/linphonerc\", this);\n mCore.addListener(mCoreListener);\n // Core is ready to be configured\n configureCore();\n }\n\n @Override\n public int onStartCommand(Intent intent, int flags, int startId) {\n super.onStartCommand(intent, flags, startId);\n\n // If our Service is already running, no need to continue\n if (sInstance != null) {\n return START_STICKY;\n }\n\n // Our Service has been started, we can keep our reference on it\n // From now one the Launcher will be able to call onServiceReady()\n sInstance = this;\n\n // Core must be started after being created and configured\n mCore.start();\n // We also MUST call the iterate() method of the Core on a regular basis\n TimerTask lTask =\n new TimerTask() {\n @Override\n public void run() {\n mHandler.post(\n new Runnable() {\n @Override\n public void run() {\n if (mCore != null) {\n mCore.iterate();\n }\n }\n });\n }\n };\n mTimer = new Timer(\"Linphone scheduler\");\n mTimer.schedule(lTask, 0, 20);\n\n return START_STICKY;\n }\n\n @Override\n public void onDestroy() {\n mCore.removeListener(mCoreListener);\n mTimer.cancel();\n mCore.stop();\n // A stopped Core can be started again\n // To ensure resources are freed, we must ensure it will be garbage collected\n mCore = null;\n // Don't forget to free the singleton as well\n sInstance = null;\n\n super.onDestroy();\n }\n\n @Override\n public void onTaskRemoved(Intent rootIntent) {\n // For this sample we will kill the Service at the same time we kill the app\n stopSelf();\n\n super.onTaskRemoved(rootIntent);\n }\n\n private void configureCore() {\n // We will create a directory for user signed certificates if needed\n String basePath = getFilesDir().getAbsolutePath();\n String userCerts = basePath + \"/user-certs\";\n File f = new File(userCerts);\n if (!f.exists()) {\n if (!f.mkdir()) {\n Log.e(userCerts + \" can't be created.\");\n }\n }\n mCore.setUserCertificatesPath(userCerts);\n }\n\n private void dumpDeviceInformation() {\n StringBuilder sb = new StringBuilder();\n sb.append(\"DEVICE=\").append(Build.DEVICE).append(\"\\n\");\n sb.append(\"MODEL=\").append(Build.MODEL).append(\"\\n\");\n sb.append(\"MANUFACTURER=\").append(Build.MANUFACTURER).append(\"\\n\");\n sb.append(\"SDK=\").append(Build.VERSION.SDK_INT).append(\"\\n\");\n sb.append(\"Supported ABIs=\");\n for (String abi : Version.getCpuAbis()) {\n sb.append(abi).append(\", \");\n }\n sb.append(\"\\n\");\n Log.i(sb.toString());\n }\n\n private void dumpInstalledLinphoneInformation() {\n PackageInfo info = null;\n try {\n info = getPackageManager().getPackageInfo(getPackageName(), 0);\n } catch (PackageManager.NameNotFoundException nnfe) {\n Log.e(nnfe);\n }\n\n if (info != null) {\n Log.i(\n \"[Service] Linphone version is \",\n info.versionName + \" (\" + info.versionCode + \")\");\n } else {\n Log.i(\"[Service] Linphone version is unknown\");\n }\n }\n\n private void copyIfNotExist(int ressourceId, String target) throws IOException {\n File lFileToCopy = new File(target);\n if (!lFileToCopy.exists()) {\n copyFromPackage(ressourceId, lFileToCopy.getName());\n }\n }\n\n private void copyFromPackage(int ressourceId, String target) throws IOException {\n FileOutputStream lOutputStream = openFileOutput(target, 0);\n InputStream lInputStream = getResources().openRawResource(ressourceId);\n int readByte;\n byte[] buff = new byte[8048];\n while ((readByte = lInputStream.read(buff)) != -1) {\n lOutputStream.write(buff, 0, readByte);\n }\n lOutputStream.flush();\n lOutputStream.close();\n lInputStream.close();\n }\n}\n\n\nI hope, that will help somebody, because I spend a lot of time trying to find it!",
2020-01-17T03:48:16
yy